package com.hoopchina;

import com.hoopchina.ui.main.IInitListener;
import com.hoopchina.ui.main.IWidgetEventListener;
import com.hoopchina.ui.main.Splash;
import com.hoopchina.ui.main.TabBar;
import com.hoopchina.ui.main.WidgetEventArgs;

/**
 * Event observer of main activity, the wrapper of all kinds of events
 * @author Si Wei
 * @see IWidgetEventListener, IInitListener
 */
public class EventObserver implements IWidgetEventListener, IInitListener {
	private MainActivity               mMainAct;            // the only event listener
	
	// constructor
	public EventObserver( MainActivity aMainAct ) {
		mMainAct = aMainAct;
	}
	
	/**
	 * From IWidgetEventListener
	 */
	@Override
	public void onEventOccured(WidgetEventArgs aEventArgs) {
		Object sender = aEventArgs.Sender;
		if ( sender == null ) {
			return;
		}
		// tabbar button clicked
		if ( aEventArgs.Sender instanceof TabBar ) {
			mMainAct.onTabbarButtonClicked( ( Integer )aEventArgs.Data );
		}
		// splash animation ended
		else if ( aEventArgs.Sender instanceof Splash ) {
			mMainAct.onSplashClosed();
		}
	}
	
	/**
	 * From IInitListener, initialization started
	 */
	@Override
	public void onInitStarted() {
		// no implementation
	}
	
	/**
	 * From IInitListener, initialization message updated
	 */
	@Override
	public void updateMessage( String aMessage ) {
		// no implementation
	}
	
	/**
	 * From IInitListener, initialization ended
	 */
	@Override
	public void onInitEnded() {
		// no implementation
	}
}
